package com.hzhr.iot.web.controller;

import com.hzhr.iot.device.sdk.service.Device_ProdFactoryService;
import com.hzhr.iot.user.sdk.model.company_name.Company_NameModel;
import com.hzhr.iot.user.sdk.service.User_Company_NameService;
import com.hzhr.iot.web.Global;
import com.hzhr.iot.web.constant.UserOptions;
import com.hzhr.iot.web.controller.base.BaseController;
import com.hzhr.iot.web.model.response.BaseResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RequestMapping("/option")
@Api(description = "通用字典表")
@RestController
public class OptionController extends BaseController {
    @Autowired
    Device_ProdFactoryService device_prodFactoryService;
    @Autowired
    User_Company_NameService user_company_nameService;
    @Autowired
    UserOptions userOptions;

    @Autowired
    Global global;


    @ApiOperation(value = "通用字典表列表", notes = "通用字典表列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum", value = "当前页码",required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "pageSize", value = "单页面条数", required =false,dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "uat", value = "用户登录令牌", dataType = "String", required = true, paramType = "query"),
            @ApiImplicitParam(name = "name", value = "name", dataType = "String", required = false, paramType = "query")
    })
    @RequestMapping(value = "/getinstallfactory", method = RequestMethod.POST)
    BaseResponse getinstallfactory(@RequestParam(value ="pageNum", required = false,defaultValue = "1") int pageNum,
                                   @RequestParam(value = "pageSize", required = false,defaultValue = "10") int pageSize,
                                   @RequestParam(value = "uat", required = true) String uat,
                                   @RequestParam(value = "name", required = false) String name) throws Exception {
        String token = getToken();

        Map<String, String> header = new HashMap<>();
        header.put("token", global.getFirstToken());
        Map<String, Object> query = new HashMap<>();
        query.put("show", "list");
        query.put("show_info", true);
        query.put("equal_type", userOptions.getCode("COMPANY_TYPE", "IOT_DEVICE_COMPANY"));
        List<Company_NameModel> companys = user_company_nameService.get(header, query).getModelList();

        Map<String, Object> result = new HashMap<>();
        List<Map<String, Object>> dataList = new ArrayList<>();
        for (Company_NameModel company :
                companys) {
            Map<String, Object> dataItem = new HashMap<>();
            dataItem.put("id", company.getId());
            dataItem.put("des", company.getShortName());
            dataList.add(dataItem);
        }
        result.put("dataList", dataList);
        return new BaseResponse("0", "成功",result);
    }

    @ApiOperation(value = "通用字典表列表", notes = "通用字典表列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum", value = "当前页码",required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "pageSize", value = "单页面条数", required =false,dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "typeCode", value = "typeCode", dataType = "String", required = false, paramType = "query"),
            @ApiImplicitParam(name = "typeName", value = "typeName", dataType = "String", required = false, paramType = "query"),
            @ApiImplicitParam(name = "code", value = "code", dataType = "String", required = false, paramType = "query"),
            @ApiImplicitParam(name = "uat", value = "用户登录令牌", dataType = "String", required = true, paramType = "query"),
            @ApiImplicitParam(name = "name", value = "name", dataType = "String", required = false, paramType = "query")
    })
    @RequestMapping(value = "/getlist", method = RequestMethod.POST)
    BaseResponse getlist(@RequestParam(value ="pageNum", required = false) Integer pageNum,
                         @RequestParam(value = "pageSize", required = false) Integer pageSize,
                         @RequestParam(value ="typeCode", required = false) String typeCode,
                         @RequestParam(value = "typeName", required = false) String typeName,
                         @RequestParam(value = "uat", required = true) String uat,
                         @RequestParam(value = "code", required = false) String code,
                         @RequestParam(value = "name", required = false) String name) throws Exception {
        Map<String, Object> result = new HashMap<>();
        result.put("pageNum",pageNum);
        result.put("pageSize",pageSize);
        return new BaseResponse("0", "成功", result);
    }
}
